<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var obj = {
            name: "edward",
            age: 100,
            sex: 'man',
            print: 'eat'
        };

        var proxy = new Proxy(obj, {
            get: function (target, property, receiver) {
                if (property === 'sex') {
                    return '这个数据是绝密, 目前不能获取';
                } else {
                    console.log(`某人获取了一个${property}键, 请注意查收`);
                    return Reflect.get(...arguments);
                }
            },
            set: function (target, property, newValue, receiver) {
                if (property === 'age') {
                    if (typeof newValue === 'number') {
                        Reflect.set(...arguments);
                    } else {
                        throw new Error('Age cannot be set to other types of non number data');
                    }
                } else {
                    console.log(`某人设置了一个${property}键, 请注意观察`);
                    Reflect.set(...arguments);
                }
            }
        });
    </script>
</body>

</html>